package com.enation.app.web.tag.member;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.enation.app.web.core.model.Member;
import com.enation.app.web.core.service.IMemberManager;
import com.enation.framework.context.webcontext.ThreadContextHolder;
import com.enation.framework.taglib.BaseFreeMarkerTag;

import freemarker.template.TemplateModelException;

/**
 * 
 * @function 检测用户是否存在
 * @author 小韦
 * @time 2017年1月15日 下午6:24:27
 */
@Component
public class MemberExistTag extends BaseFreeMarkerTag {

	@Autowired
	private IMemberManager memberManager;

	@Override
	protected Object exec(Map params) throws TemplateModelException {

		HttpServletRequest request = ThreadContextHolder.getHttpRequest();
		HttpSession session = request.getSession();
		Member member = (Member) session.getAttribute("member");
		if (member != null) {
			int count = this.memberManager.checkIsRegister(member
					.getStudent_number());
			if (count == 0) {
				session.removeAttribute("member");
			}
		}

		return true;

	}
}
